<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html style="height: auto; min-height: 100%;">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>天津市西青医院满意度调查问卷</title>
    <!-- Tell the browser to be responsive to screen width -->
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="<%=basePath%>bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="<%=basePath%>bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="<%=basePath%>bower_components/Ionicons/css/ionicons.min.css">

    <!-- Theme style -->
    <link rel="stylesheet" href="<%=basePath%>dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="<%=basePath%>dist/css/skins/_all-skins.min.css">
    <!-- Validator style -->
    <link href="<%=basePath %>bootstrap/bootstrapvalidator/dist/css/bootstrapValidator.min.css" rel="stylesheet"/>
    <link href="<%=basePath %>bootstrap/bootstrap-table/dist/bootstrap-table.css" rel="stylesheet"/>
    <link href="<%=basePath %>bootstrap/bootoast/dist/bootoast.min.css" rel="stylesheet"/>
</head>
<body class="skin-blue sidebar-mini" style="height: auto; min-height: 100%;">
<div class="wrapper" style="height: auto; min-height: 100%;">
    <!-- header头部页面 -->
    <jsp:include page="../commend/top.jsp"/>
    <!-- Left side column. contains the logo and sidebar -->
    <jsp:include page="../commend/left.jsp"/>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper" style="min-height: 800px;">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>

                <small>用户管理</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li class="active">用户管理</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <!-- Info boxes -->
            <!-- Main row -->
            <div class="row">
                <div class="col-md-12">
                    <div class="box">
                        <div class="box-header with-border">
                            <h3 class="box-title">用户列表</h3>
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body ">
                            <div class="row ">
                                <div class="col-md-12">
                                    <div id="toolbar" class="btn-group">
                                        <button id="btn_save" type="button" class="btn btn-block btn-primary" >
                                            添加
                                        </button>

                                    </div>
                                    <table
                                            id="cycletable"
                                            data-toggle="table"
                                            data-url="<%=basePath%>/user/selectAllUser"
                                            data-toolbar="#toolbar"
                                            data-pagination="true"
                                            data-cache="false"
                                            data-search="true"
                                            style="font-size:100%;">
                                        <thead>
                                        <tr>
                                            <th data-field="username" data-align="center" data-valign="middle">用户名</th>
                                            <th data-field="realName" data-align="center" data-valign="middle">姓名</th>
                                            <th data-field="tDept.name" data-align="center" data-valign="middle">科室名称</th>
                                            <th data-field="type" data-formatter="typeformat" data-align="center" data-valign="middle">用户类型</th>
                                            <th data-field="status" data-formatter="stateformat" data-align="center" data-valign="middle">状态</th>
                                            <th data-field="id"  data-align="center" data-valign="middle" data-formatter="operateformat" data-events="operateEvent">操作</th>

                                        </tr>
                                        </thead>
                                    </table>
                                </div>
                            </div>
                            <!-- /.row -->
                        </div>
                        <!-- ./box-body -->
                        <div class="box-footer">
                            <div class="row">

                            </div>
                            <!-- /.row -->
                        </div>
                        <!-- /.box-footer -->
                    </div>
                    <!-- /.box -->
                </div>
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
        <div class="modal fade" id="modalTable" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">用户管理</h4>
                    </div>
                    <div class="modal-body">
                            <!-- form start -->
                            <form class="form-horizontal" id="myform">
                                <div class="box-body">
                                    <div class="form-group">
                                        <label for="username" class="col-sm-2 control-label">用户名</label>

                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" id="username" name="username" placeholder="用户名">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="realName" class="col-sm-2 control-label">姓名</label>

                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" id="realName"  name="realName" placeholder="姓名">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="deptId" class="col-sm-2 control-label">科室</label>

                                        <div class="col-sm-10">
                                            <select class="form-control" name="deptId" id="deptId">
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="normal" class="col-sm-2 control-label">类型</label>
                                        <div class="col-sm-10">
                                            <div class="radio">
                                                <label><input type="radio" name="type" id="normal" value="B" checked> 普通用户</label>
                                                <label><input type="radio" name="type" value="A"> 管理员</label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="isopen" class="col-sm-2 control-label">状态</label>
                                        <div class="col-sm-10">
                                            <div class="radio">
                                                <label><input type="radio" name="status" id="isopen" value="1" checked> 启用</label>
                                                <label><input type="radio" name="status" value="0"> 禁用</label>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- /.box-body -->
                                <input type="hidden" name="id">
                            </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default"  id="btn_sure">确定</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /.content-wrapper -->
    <!-- footer-->
    <jsp:include page="../commend/footer.jsp"/>





</div>

<!-- jQuery 3 -->
<script src="<%=basePath %>bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="<%=basePath %>bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- FastClick -->
<script src="<%=basePath %>bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="<%=basePath %>dist/js/adminlte.min.js"></script>
<!-- ChartJS -->
<script src="<%=basePath %>bower_components/chart.js/Chart.js"></script>

<!-- AdminLTE for demo purposes -->
<script src="<%=basePath %>dist/js/demo.js"></script>
<!-- Validator 3.3.7 -->
<script src="<%=basePath %>bootstrap/bootstrapvalidator/dist/js/bootstrapValidator.min.js"></script>
<script src="<%=basePath %>bootstrap/bootstrapvalidator/dist/js/language/zh_CN.js"></script>
<!-- bootstrap-table -->
<script src="<%=basePath %>bootstrap/bootstrap-table/dist/extensions/x-editable/bootstrap-editable.min.js"></script>
<script src="<%=basePath %>bootstrap/bootstrap-table/dist/extensions/x-editable/bootstrap-table.min.js"></script>
<script src="<%=basePath %>bootstrap/bootstrap-table/dist/extensions/x-editable/bootstrap-table-editable.min.js"></script>
<script src="<%=basePath %>bootstrap/bootstrap-table/dist/locale/bootstrap-table-zh-CN.min.js"></script>
<!-- bootbox -->
<script src="<%=basePath %>bootstrap/bootbox/bootbox.min.js"></script>
<script src="<%=basePath %>bootstrap/bootoast/dist/bootoast.min.js"></script>
<script src="<%=basePath %>bootstrap/commend/initcommend.js"></script>

<script type="text/javascript">
    $(function() {
        $.get(getRootPath_web()+"/dept/selectAllDept",{},function (data) {
            $.each(data,function (index, obj) {
                $("#deptId").append("<option value='"+obj.id+"'>"+obj.name+"</option>");
            })
        },"json")

        $('#btn_save').click(function () {
            $("#myform")[0].reset()
            $("input[name=id]").val('');
            $("#modalTable").modal({
                backdrop: 'static',
                keyboard: false
            });

        });

        $("#btn_sure").click(function () {
            var url = '';
            if($("input[name=id]").val() == ''){
                url = getRootPath_web()+'/user/addTUser';
            }else{
                url = getRootPath_web()+'/user/updateTUser';
            }
            $.post(url,$("#myform").serialize(),function (data) {
                if(data){
                    bootoast.toast({
                        message: '保存成功!',
                        type: 'info',
                        position: 'top-center'
                    });
                }else{
                    bootoast.toast({
                        message: '保存失败!',
                        type: 'info',
                        position: 'top-center'

                    });
                }
                $("#modalTable").modal("hide");
                $("#cycletable").bootstrapTable('refresh')
            },'json')

        })
    })

    function typeformat(value, row) {
        return value == 'A'?'管理员':'普通用户';
    }
    function stateformat(value, row) {
        return row.status == 1?'启用':'禁用';
    }
    function operateformat(value, row) {
        var buttonarray = new Array();
        if(row.status == 1){
            buttonarray[0] = '<button type="button" class="RoleOfedit btn btn-primary  btn-sm" >禁用</button>';
        }else{
            buttonarray[0] = '<button type="button" class="RoleOfedit btn btn-primary  btn-sm" >启用</button>';
        }
        buttonarray[1] = '<button type="button" class="RoleOfupdate btn btn-primary  btn-sm" style="margin-left: 10px">修改</button>';

        return buttonarray.join('');
    }
    window.operateEvent = {
        'click .RoleOfedit': function (e, value, row, index) {
            $.post(getRootPath_web()+'/user/changTUserStatus',{'id':row.id},function (data) {
                if(data){
                    bootoast.toast({
                        message: '操作成功!',
                        type: 'info',
                        position: 'top-center'

                    });
                }else{
                    bootoast.toast({
                        message: '操作失败!',
                        type: 'info',
                        position: 'top-center'

                    });
                }
                $("#cycletable").bootstrapTable('refresh')
            },'json')
        },
        'click .RoleOfupdate': function (e, value, row, index) {
            $("#myform")[0].reset()
            $.post(getRootPath_web()+'/user/getTUserById',{'id':row.id},function (data) {
                $("input[name=username]").val(data.username);
                $("input[name=realName]").val(data.realName);
                $("#deptId").val(data.deptId);
                $("input[name='type']").attr('checked', false);
                $("input[name='status']").attr('checked', false);
                $("input[name='type'][value='"+data.type+"']").attr('checked', 'checked');
                $("input[name='status'][value='"+data.status+"']").attr('checked', 'checked');
                $("input[name=id]").val(data.id);
                $("#modalTable").modal({
                    backdrop: 'static',
                    keyboard: false
                });
            },'json')

        }
    }

</script>
</body>
</html>
